package org.example.listener;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import org.example.entity.ABCar;
import org.example.entity.ACar;
import org.example.entity.BCar;

import java.util.ArrayList;
import java.util.List;
import static org.example.until.StringSimilarity.find;
import static org.example.until.StringSimilarity.mapNotFount;

//读取文档的监听器类
public class BCarListener extends AnalysisEventListener<BCar> {
    public static List<ABCar> abCars = new ArrayList<>();
    @Override
    public void invoke(BCar bCar, AnalysisContext analysisContext) {//b每读取一个就去a构建出的map中去寻找
        ABCar abCar = new ABCar();
        abCar.setBName(bCar.getBName());
        abCar.setAName(mapNotFount(bCar.getBName()));//去寻找当前的b对应的a，这里会返回a的名字
        abCars.add(abCar);//准备写对象
        ExcelWriterBuilder writeBook = EasyExcel.write("新建XLSX 工作表1.xlsx", ABCar.class);
        //工作表对象
        ExcelWriterSheetBuilder sheet = writeBook.sheet();
        //写
        sheet.doWrite(abCars);
    }
    /**
     * 读取完整个文档之后调用的方法
     *
     * @param analysisContext
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
    }
}